var laypage = layui.laypage;

var pageNumber = getQueryString("pageNumber") || 1;
var pageSize = getQueryString("pageSize") || 12;

document.title = "t-io：博客列表";


var table = layui.table;


$(function() {
    var bloguid = null;

    var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块
    element.render();

    var form = layui.form;
    form.render();

    form.on('checkbox(onlymine)', function(data){
        if (curruser) {
            if ($("#onlymine")[0].checked) {
                bloguid = curruser.id;
            } else {
                 bloguid = null;
            }
            page();
        }
    });  

    

    
    /**
     * 分页查询
     * @param {} pageNumber 
     * @param {*} pageSize 
     */
    function page() {
        table.render({
            elem: '#itemlist'
            // , skin: 'line' //行边框风格
            // , height: 620
            , limit: pageSize
            , limits: layui_page_limits
            // , totalRow: true   //是否开启合计行区域。layui 2.4.0 新增
            , request: {
                pageName: 'pageNumber' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }

            ,where:{uid: bloguid}
            , done: function (res, curr, count) {

                layui_page_done(res.pageNumber, res.pageSize);
            }
            // , height: 1500
            , url: path('/blog/page') //数据接口
            //, parseData
            , parseData: layui_page_parseData
            // , data: _data
            // , limit: _data.length
            , page: true //开启分页
            , cols: [[ //表头
                {
                    field: 'avatar', width: 200, title: '作 者', sort: false, templet: function (d) {
                        if (!d.avatar) {
                            d.avatar = "/img/1.png";
                        }
                        var xx = res_url(d.avatar);
                        var avatar_html = '<img class="layui-anim layui-anim-scaleSpring" alt="true" src="' + xx + '" style="width: 35px; height: 35px; border-radius: 50%; margin-right:4px;">';
                        if (d.url) {
                            return "<a href='" + d.url + "' target='_blank'><div class='layui-elip'>" + avatar_html + d.nick + "</div></a>";
                        } else {
                            return avatar_html + d.nick;
                        }
                    }
                },
                {
                    field: 'title',  title: '标 题', sort: false, templet: function (d) {
                        var html = '<a target="_blank" href="/' + d.id + '" title="' + d.title + '"><div style="font-size:16px;" class="layui-elip">' + d.title + "</div></a>";
                        return html;
                    }
                },
                {
                    field: 'createtime', width: 200, title: '创建时间', templet: function (d) {
                        return d.createtime;
                    }
                }
            ]]
        });

    }

    page();
});




